<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',border:false">
		<table style="margin-left: 20px;margin-top: 20px;">
				<form id="uuTestForm">
				<tr>
					<td>设备列表:</td>
					<td>
						<@eu.comboBox id="testParkDeviceName" url="parkingDevice.do?loadDevices" name="deviceName" required="true" />
					</td>
					
				</tr>
				</form>
				<tr>
					<td>
						<a href="javascript:void(0)" class="easyui-linkbutton" style="background-color: #c5dbf6;" plain="true" onclick="deviceOff()">车锁下降</a>
					</td>
					<td>
						<a href="javascript:void(0)" class="easyui-linkbutton" style="background-color: #c5dbf6;" plain="true" onclick="deviceOn()">车锁升起</a>
					</td>
				</tr>	
		</table>
		<hr />
		<table>
			<tr>
				<td>模拟DTU主动上报设备状态内容:</td>
				<td>
					<textarea id="parkDevPostStatusContent" style="height: 300px;width:350px" rows="6"  name="cmd" class="easyui-validatebox" >[{"aid":"a1","gwid":"f0001","ukid": "a0101","tag":"ulock", "st":{ "onoff":0,"kwh":1, "car":0}}]</textarea>
				</td>
				<td>
					<a href="javascript:void(0)" class="easyui-linkbutton" style="background-color: #c5dbf6;" plain="true" onclick="testParkDevPostStatusContent()">上报>></a>
				</td>
				<td>处理结果:</td>
				<td>
					<textarea id="parkDevPostStatusContentReturn" style="height: 300px;width:350px" rows="6"  name="cmd" class="easyui-validatebox" ></textarea>
				</td>
			</tr>
			
			<tr>
				<td>模拟DTU查询设备状态内容:</td>
				<td>
					<textarea id="parkDevSearchStatusContent" style="height: 300px;width:350px" rows="6"  name="cmd" class="easyui-validatebox" >{"tag":"ulock","aid":"a1","gwid":"f0001","ask":"123456"}</textarea>
				</td>
				<td>
					<a href="javascript:void(0)" class="easyui-linkbutton" style="background-color: #c5dbf6;" plain="true" onclick="testParkDevSearchStatusContent()">查询>></a>
				</td>
				<td>查询结果:</td>
				<td>
					<textarea id="parkDevSearchStatusContentReturn" style="height: 300px;width:350px" rows="6"  name="cmd" class="easyui-validatebox" ></textarea>
				</td>
			</tr>
		</table>
	</div>
	
</div>
<script type="text/javascript">
	function deviceOff() {
		 var validate = $('#testParkDeviceName').combobox('getValue');
		 printLog(validate);
		 if(validate) {
			 onLoadingHandler(function() {
					$.post("parkTest.do?deviceOff",{id:$('#testParkDeviceName').combobox('getValue')}, function(result) {
						openMsg({msg:result.msg,timeout:5000});
						removeload();
			     	}, "JSON");
				});
		 }else {
			 showMsg("请选择操作设备",3000);
		 }
		
	}
	
	function deviceOn() {
		 var validate = $('#testParkDeviceName').combobox('getValue');
		 if(validate) {
			 onLoadingHandler(function() {
					$.post("parkTest.do?deviceOn",{id:$('#testParkDeviceName').combobox('getValue')}, function(result) {
						openMsg({msg:result.msg,timeout:5000});
						removeload();
			     	}, "JSON");
				});
		 }else {
			 showMsg("请选择操作设备",3000);
		 }
		
		
	}
	
	
	function testParkDevPostStatusContent() {
// 		req.send('[{"aid":"a1","gwid":"f0001","ukid": "a0101","tag":"ulock", "st":{ "on-off":0,"kwh":1, "car":0}}]');
// '[{"aid":"a1","gwid":"f0001","ukid": "a0101","tag":"ulock", "st":{ "onoff":0,"kwh":1, "car":0}}]'
		$('#parkDevPostStatusContentReturn').val("");
		onLoadingHandler(function() {
			callByXMLHttpRequest("Device/DeviceComm.ashx?actionType=1",$('#parkDevPostStatusContent').val(),function(data) {
				removeload();
				if(data.currentTarget.readyState == "4") {
					if(data.currentTarget.status == "200") {
						$('#parkDevPostStatusContentReturn').val(data.currentTarget.responseText);
					} else {
						$('#parkDevPostStatusContentReturn').val("操作失败!");
					}
				}
				
			});
		});
		
	}
	
	function testParkDevSearchStatusContent() {
		//{"tag":"ulock","aid":"a1","gwid":"f0001","ask":"all"}
		//{"tag":"ulock","aid":"a1","gwid":"f0001","ask":"123456"}
		$('#parkDevSearchStatusContentReturn').val("");
		onLoadingHandler(function() {
			callByXMLHttpRequest("Device/DeviceComm.ashx?actionType=2",$('#parkDevSearchStatusContent').val(),function(data) {
				removeload();
				if(data.currentTarget.readyState == "4") {
					if(data.currentTarget.status == "200") {
						$('#parkDevSearchStatusContentReturn').val(data.currentTarget.responseText);
					} else {
						$('#parkDevSearchStatusContentReturn').val("操作失败!");
					}
				}
				
			});
		});
	}
	
	function callByXMLHttpRequest(url,data,callFun) {
	    if (window.XMLHttpRequest){ 
	      req = new XMLHttpRequest(); 
	    } 
	    else if (window.ActiveXObject){ 
	      req = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    req.open("Post",url,true); 
	    req.onreadystatechange = callFun; 
	    
	    req.send(data);
	}
	
	function callback(data) {
		if(data.currentTarget.readyState == "4") {
			if(data.currentTarget.status == "200") {
				alert(data.currentTarget.responseText);
			} else {
				alert("网络不稳定，请稍后再试!");
			}
		}
	}

  </script>